package com.wolves.career.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wolves.career.entity.ProPlanning;
import com.wolves.career.service.ProPlanningService;
import com.wolves.career.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-31
 */
@RestController
@RequestMapping("/career/planning")
@CrossOrigin
public class ProPlanningController {

    @Autowired
    private ProPlanningService planningService;

    @GetMapping("/{id}")
    public R deletePlanning(@PathVariable String id){
        planningService.removeById(id);
        return R.ok();
    }

    @PutMapping("/plan")
    public R updatePlanning(@RequestBody ProPlanning planning){
        planningService.updateById(planning);
        return R.ok();
    }

    //前端需要传过来专业的id
    @PostMapping("/plan")
    public R addPlanning(@RequestBody ProPlanning proPlanning){
        planningService.save(proPlanning);
        return R.ok();
    }

    //根据id获取职业规划路线
    @GetMapping("/plan/{id}")
    public R getPlanningById(@PathVariable String id){
        ProPlanning plan = planningService.getById(id);
        return R.ok().data("plan",plan);
    }

    // TODO: 2021/10/31 这里需要加入条件查询
    @PostMapping("/list/{pageNo}/{limit}")
    public R listPlan(@PathVariable long pageNo, @PathVariable long limit){
        Page<ProPlanning> page = new Page<>(pageNo,limit);
        IPage<ProPlanning> planPage = planningService.page(page, null);
        return R.ok().data("records",planPage.getRecords()).data("total",planPage.getTotal());
    }

}

